/**
 * 给数组元素按照个数分组
 * @param {*} arr 数组
 * @param {*} count 按个数分组
 * @returns 
 */
export function groupArray(arr = [], count = 1) {
    const res = []
    if (count >= 1 && Array.isArray(arr)) {
        let s = 0
        while (s < arr.length) {
            res.push(arr.slice(s, s + count))
            s += count
        }
        return res
    } else {
        console.error('count必须为正整数')
    }
}
/**
 * 数组分组对象，按照回调返回值分组
 * @param {*} arr 数组
 * @param {*} fn 回调函数
 * @returns 
 */
export function groupMap(arr = [], fn = () => 'default') {
    const map = {}
    arr.forEach((e, index) => {
        const res = fn(e, index)
        const groupArr = map[res] || []
        groupArr.push(e)
        if (!map[res]) {
            map[res] = groupArr
        }
    })
    return map
}